package com.syt.cellphone.information.data.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.syt.cellphone.information.data.pojo.PhoneGroup

/**
 *  @author: syt
 *  创建时间: 2020/8/31 15:10
 *  @功能
 *  @version v1.0
 */
@Dao
interface PhoneGroupDao {

    /**
     * id 查询 group
     */
    @Query("select * from phone_groups where groupId = :id")
    fun getById(id: Int) : PhoneGroup?

    @Query("select * from phone_groups order by 'order'")
    fun liveDataAll(): LiveData<List<PhoneGroup>>

    /**
     * 分组数量总和
     */
    @get:Query("select sum(groupId) from phone_groups")
    val idsSum: Int

    /**
     * 分组数据集
     */
    @get:Query("select * from phone_groups order by 'order'")
    val all: LiveData<List<PhoneGroup>>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(vararg phoneGroup: PhoneGroup)

    @Update
    fun update(vararg phoneGroup: PhoneGroup)

    @Delete
    fun delete(vararg phoneGroup: PhoneGroup)
}